//
//  WSAuthorItem.m
//  GroupFourFM
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSAuthorItem.h"
#import <UIImageView+WebCache.h>
#import "WSBmob.h"

@interface WSAuthorItem ()

@property (nonatomic, strong) WSBaseCollectionLabel *titleLabel;

@property (nonatomic, strong) UIButton *button;

@end

@implementation WSAuthorItem

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createCell];
    }
    
    return self;
}

- (void)createCell
{
    
    //    self.backgroundColor = COLOR_SELECTED;
    
    UIView *view = [[UIView alloc] init];
    view.layer.borderColor = [UIColor colorWithRed:0.93 green:0.94 blue:0.95 alpha:1].CGColor;
    view.layer.borderWidth = 1;
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@0);
        make.top.mas_equalTo(@0);
        make.height.width.equalTo(self.contentView.mas_width);
    }];
    
    self.headImageView = [[UIImageView alloc] init];
    [view addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(view);
        make.height.width.equalTo(view.mas_height).offset(-5);
    }];
    
    self.titleLabel = [[WSBaseCollectionLabel alloc] init];
    self.titleLabel.backgroundColor = CLEAR;
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(view);
        make.top.equalTo(view.mas_bottom).offset(5);
        make.width.equalTo(view);
        make.height.equalTo(self.contentView.mas_height).multipliedBy(0.2);
    }];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.headImageView);
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.width.equalTo(self.headImageView).multipliedBy(0.7);
        make.bottom.equalTo(self.contentView);
    }];
}

-(void)setAuthorModel:(WSAuthorModel *)authorModel
{
    _authorModel = authorModel;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:authorModel.smallLogo] placeholderImage:PLACEHOLDER_CELL_SAME];
    if (_authorModel.objectId != nil) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse_sel"] forState:UIControlStateNormal];
    } else {
        [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse"] forState:UIControlStateNormal];
    }
    self.headImageView.tag = _authorModel.uid;
    self.titleLabel.text = authorModel.nickname;
}

#pragma mark - 关注
- (void)buttonAction:(UIButton *)send {

    [self.delegate collectedWithModel:_authorModel];
}

@end
